public class Test{

    public static void main(String[] args) throws Exception{
        //自己改下路径
		File dirs = new File("D:\\NewFolder\\J2EE\\workplace-J2EE\\new\\DigitalAssets\\src\\main\\java");
		System.err.println(sumLines(dirs) + " Lines");
	}
	
	private static long sumLines(File file) throws Exception{
		if(file.isFile() && file.getName().endsWith(".java")) {
			FileReader fileReader = new FileReader(file);
			BufferedReader bufferedReader = new BufferedReader(fileReader);
			Stream<String> lines = bufferedReader.lines();
			long count = lines.count();
			bufferedReader.close();
			return count;
		}else if(file.isDirectory()){
			int sum = 0;
			File[] files = file.listFiles();
			for (File f : files) {
				sum += sumLines(f);
			}
			return sum;
		} else {
			return 0;
		}
	}
}